﻿// =================================================================== 
// 数据访问层(GDIT.DAL)
//====================================================================
// 文件：DLinkInfo.cs
// 项目名称：学院网站
// 创建时间：2012-08-08
// 负责人：ChenZhiGang
//引用DevExpress.Data.Filtering，DevExpress.Xpo程序集
// 程序集介绍：链接信息数据访问层
// ===================================================================
using GDIT.Model;
using DevExpress.Data.Filtering;
using DevExpress.Xpo;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GDIT.Pattern;
using System.Data;

namespace GDIT.DAL
{
    public class DLinkInfo : ILinkInfo
    {

        private XpoHelper.Test<Mtb_LinkInfo> userOperation = null;

        /// <summary>
        /// 新增链接对象
        /// </summary>
        /// <param name="link">需要新增的链接对象</param>
        /// <returns>1：新增成功  0：新增失败</returns>
        public int InsertLinkInfo(Mtb_LinkInfo link)
        {
            return XpoHelper.SaveAdded(link);
        }

        /// <summary>
        /// 更新链接对象
        /// </summary>
        /// <param name="link">需要的链接对象</param>
        /// <returns>1：更新成功  0：更新失败</returns>
        public int UpdateLinkInfo(Mtb_LinkInfo link)
        {
            userOperation = new XpoHelper.Test<Mtb_LinkInfo>();
            XPCollection xp = userOperation.Operation("OID", link.OID);
            foreach (Mtb_LinkInfo b in xp)
            {
                b.LinkName = link.LinkName;
                b.LinkAddress = link.LinkAddress;
                return XpoHelper.SaveModified(b);
            }
            return 0;
        }

        /// <summary>
        /// 删除链接对象
        /// </summary>
        /// <param name="link">需要的链接对象</param>
        /// <returns>1：删除成功  0：删除失败</returns>
        public int DeleteLinkInfo(Mtb_LinkInfo link)
        {
            userOperation = new XpoHelper.Test<Mtb_LinkInfo>();
            return userOperation.Delete(link.OID);
        }

        /// <summary>
        /// 查询所有链接对象
        /// </summary>
        /// <returns>所有链接对象集合</returns>
        public IDataReader SelectAllLinkInfo()
        {
            return XpoHelper.SelectID("select li.OID, LinkName, LinkAddress, LinkTypeName from dbo.Mtb_LinkInfo as li join dbo.Mtb_LinkType as lt on li.[Type] = lt.OID");
        }

        /// <summary>
        /// 查询单一链接对象
        /// </summary>
        /// <param name="link">需要查询的链接对象条件</param>
        /// <returns>单一链接对象</returns>
        public Mtb_LinkInfo SelectLinkInfoByLink(Mtb_LinkInfo link)
        {
            Mtb_LinkInfo bulletin = null;
            userOperation = new XpoHelper.Test<Mtb_LinkInfo>();
            XPCollection xp = userOperation.Operation("OID", link.OID);
            foreach (Mtb_LinkInfo b in xp)
            {
                bulletin = b;
            }
            return bulletin;
        }
    }
}
